package com.example.controller;

import com.example.common.Result;
import com.example.entity.TransferProcess;
import com.example.service.TransferProcessService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/transferProcess")
public class TransferProcessController {

    @Resource
    TransferProcessService transferProcessService;

    /**
     * 添加转接申请
     * @param transferProcess
     * @return
     */
    @PostMapping("/add")
    public Result addTransferProcess(@RequestBody TransferProcess transferProcess) {
        transferProcess.setStatus(0);
        transferProcessService.add(transferProcess);
        return Result.success();
    }

    /**
     * 根据 ID 更新转接申请
     * @param transferProcess
     * @return
     */
    @PutMapping("/update")
    public Result updateTransferProcess(@RequestBody TransferProcess transferProcess) {
        transferProcessService.updateById(transferProcess);
        return Result.success();
    }

    /**
     * 根据 ID 删除转接申请
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteTransferProcess(@PathVariable Integer id) {
        transferProcessService.deleteByUserId(id);
        return Result.success();
    }

    /**
     * 根据 student_id 查询转接申请
     * @param studentId
     * @return
     */
    @GetMapping("/getByUserId/{studentId}")
    public Result getTransferProcessById(@PathVariable String studentId) {
        List<TransferProcess> list = transferProcessService.selectByUserId(studentId);
        return Result.success(list);
    }

    /**
     * 查询所有转接申请
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(TransferProcess transferProcess) {
        List<TransferProcess> list = transferProcessService.selectAll(transferProcess);
        return Result.success(list);
    }

    /**
     * 分页查询所有转接申请
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(TransferProcess transferProcess,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<TransferProcess> page = transferProcessService.selectPage(transferProcess, pageNum, pageSize);
        return Result.success(page);
    }

}
